library("plotly")
Loading required package: ggplot2
Attaching package: ‘plotly’
The following object is masked from ‘package:ggplot2’:
last_plot
The following object is masked from ‘package:stats’:
filter
The following object is masked from ‘package:graphics’:
layout
library("plot3D")
library(tidyverse) # entorno tidy
Registered S3 methods overwritten by 'dbplyr':
method from
print.tbl_lazy
print.tbl_sql
── Attaching packages ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── tidyverse 1.3.0 ──
✓ tibble 3.1.6 ✓ dplyr 1.0.7
✓ tidyr 1.1.4 ✓ stringr 1.4.0
✓ readr 2.1.2 ✓ forcats 0.5.1
✓ purrr 0.3.4
── Conflicts ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
x dplyr::filter() masks plotly::filter(), stats::filter()
x dplyr::lag() masks stats::lag()
library(dplyr) # manejo de datos
library(GGally) # scatterplots multiples
Registered S3 method overwritten by 'GGally':
method from
+.gg ggplot2
library(rgl) # para graficos 3D
This build of rgl does not include OpenGL functions. Use
rglwidget() to display results, e.g. via options(rgl.printRglwidget = TRUE).
df = read.csv("chicos.csv", stringsAsFactors = F)
indices = (
! is.na(df$WEIGHT) &
! is.na(df$STATURE) &
! is.na(df$SEX) &
! is.na(df$RACE) &
! is.na(df$AGE.IN.YEARS) &
! is.na(df$AGE.IN.MONTHS) &
df$WEIGHT>0 &
df$STATURE>0 &
df$RACE != 0 &
(df$SEX == 1 | df$SEX==2)
)
dfFiltrados = df[indices,]
dfFiltrados$WEIGHT = dfFiltrados$WEIGHT/10
dfFiltrados$STATURE = dfFiltrados$STATURE/10
dfFiltrados$AGE.IN.MONTHS = dfFiltrados$AGE.IN.MONTHS / 12
mujeres = dfFiltrados[dfFiltrados$SEX==2, ]
hombres = dfFiltrados[dfFiltrados$SEX==1,]
whites = dfFiltrados[dfFiltrados$RACE==1,]
blacks = dfFiltrados[dfFiltrados$RACE==2,]
unique(df$SEX)
[1] 2 1
range(dfFiltrados$AGE.IN.MONTHS)
[1] 24 240
range(dfFiltrados$AGE.IN.YEARS)*12/1000
[1] 24.180 240.648
View(dfFiltrados)
plot(dfFiltrados$WEIGHT, dfFiltrados$STATURE, xlab = "Peso en KG", ylab = "Altura en CM", col=dfFiltrados$SEX)
plot(dfFiltrados$AGE.IN.MONTHS, dfFiltrados$STATURE, col=dfFiltrados$SEX, xlab = "Edad (anios)", ylab = "Altura en CM",)
cPuntos = 1000
modAlturaEnEdad = lm(STATURE~poly(AGE.IN.MONTHS,2), data=dfFiltrados)
puntosIntervalo = seq(min(dfFiltrados$AGE.IN.MONTHS), max(dfFiltrados$AGE.IN.MONTHS), (range(dfFiltrados$AGE.IN.MONTHS)[2]- range(dfFiltrados$AGE.IN.MONTHS)[1])/cPuntos)
dataFrameEvaluar = data_frame(1:(cPuntos+1))
dataFrameEvaluar = cbind(dataFrameEvaluar,puntosIntervalo)
colnames(dataFrameEvaluar) = c("ind", "AGE.IN.MONTHS")
plot(dfFiltrados$AGE.IN.MONTHS,dfFiltrados$STATURE, xlab = "Edad en anios", ylab = "Altura en CM", main="Altura en funcion de edad de toda la poblacion")
lines(puntosIntervalo, predict(modAlturaEnEdad, newdata = dataFrameEvaluar), col='red', lwd=3)
modPesoEnEdad = lm(WEIGHT~poly(AGE.IN.MONTHS,2), data=dfFiltrados)
plot(dfFiltrados$AGE.IN.MONTHS,dfFiltrados$WEIGHT, xlab = "Edad en anios", ylab = "PESO en kg", main="Peso en funcion de edad de toda la poblacion")
lines(puntosIntervalo, predict(modPesoEnEdad, newdata = dataFrameEvaluar), col='red', lwd=3)
modPesoEnEdadMuj = lm(WEIGHT~poly(AGE.IN.MONTHS,2), data=mujeres)
plot(mujeres$AGE.IN.MONTHS,mujeres$WEIGHT, xlab = "Edad en anios", ylab = "PESO en kg", main="Peso en funcion de edad de mujeres")
lines(puntosIntervalo, predict(modPesoEnEdadMuj, newdata = dataFrameEvaluar), col='red', lwd=3)
modPesoEnEdadHom = lm(WEIGHT~poly(AGE.IN.MONTHS,2), data=hombres)
plot(hombres$AGE.IN.MONTHS,hombres$WEIGHT, xlab = "Edad en anios", ylab = "PESO en kg", main="Peso en funcion de edad de hombres y mujeres", col='blue')
points(mujeres$AGE.IN.MONTHS,mujeres$WEIGHT, xlab = "Edad en anios", ylab = "PESO en kg", main="Peso en funcion de edad de hombres", col='red')
lines(puntosIntervalo, predict(modPesoEnEdadHom, newdata = dataFrameEvaluar), col='light blue', lwd=3)
lines(puntosIntervalo, predict(modPesoEnEdadMuj, newdata = dataFrameEvaluar), col='pink', lwd=3)
modAlturaEnEdadHom = lm(STATURE~poly(AGE.IN.MONTHS,2), data=hombres)
modAlturaEnEdadMuj = lm(STATURE~poly(AGE.IN.MONTHS,2), data=mujeres)
plot(hombres$AGE.IN.MONTHS,hombres$STATURE, xlab = "Edad en anios", ylab = "Altura en cm", main="Altura en funcion de edad de hombres y mujeres", col='blue')
points(mujeres$AGE.IN.MONTHS,mujeres$STATURE, col='red')
lines(puntosIntervalo, predict(modAlturaEnEdadHom, newdata = dataFrameEvaluar), col='light blue', lwd=3)
lines(puntosIntervalo, predict(modAlturaEnEdadMuj, newdata = dataFrameEvaluar), col='pink', lwd=3)
modAlturaEnEdadBlan = lm(STATURE~poly(AGE.IN.MONTHS,2), data=whites)
modAlturaEnEdadNeg = lm(STATURE~poly(AGE.IN.MONTHS,2), data=blacks)
plot(whites$AGE.IN.MONTHS,whites$STATURE, xlab = "Edad en anios", ylab = "Altura en cm", main="Altura en funcion de edad de blancos y de color")
points(blacks$AGE.IN.MONTHS,blacks$STATURE, pch=19)
lines(puntosIntervalo, predict(modAlturaEnEdadBlan, newdata = dataFrameEvaluar), col='light blue', lwd=3)
lines(puntosIntervalo, predict(modAlturaEnEdadNeg, newdata = dataFrameEvaluar), col='pink', lwd=3)
modPesoEnEdadBlan = lm(WEIGHT~poly(AGE.IN.MONTHS,2), data=whites)
modPesoEnEdadNeg = lm(WEIGHT~poly(AGE.IN.MONTHS,2), data=blacks)
plot(whites$AGE.IN.MONTHS,whites$WEIGHT, xlab = "Edad en anios", ylab = "Peso en KG", main="Peso en funcion de edad de blancos y de color")
points(blacks$AGE.IN.MONTHS,blacks$WEIGHT, pch=19)
lines(puntosIntervalo, predict(modPesoEnEdadBlan, newdata = dataFrameEvaluar), col='light blue', lwd=3)
lines(puntosIntervalo, predict(modPesoEnEdadNeg, newdata = dataFrameEvaluar), col='pink', lwd=3)
peso = dfFiltrados$WEIGHT/10
edad = dfFiltrados$AGE.IN.MONTHS/12
altura = dfFiltrados$STATURE/10
sexo = dfFiltrados$SEX
colores = c('blue','red')
fig <- plot_ly(x=~altura, y=~edad, z=~peso, marker = list(color = colores[dfFiltrados$SEX], showscale = F) , type="scatter3d", mode="markers", col=sexo, size = 1)
fig <- fig %>% layout(title = 'Peso en funcion de altura y edad'
)
fig
Warning: 'scatter3d' objects don't have these attributes: 'col'
Valid attributes include:
'connectgaps', 'customdata', 'customdatasrc', 'error_x', 'error_y', 'error_z', 'hoverinfo', 'hoverinfosrc', 'hoverlabel', 'hovertemplate', 'hovertemplatesrc', 'hovertext', 'hovertextsrc', 'ids', 'idssrc', 'legendgroup', 'legendgrouptitle', 'legendrank', 'line', 'marker', 'meta', 'metasrc', 'mode', 'name', 'opacity', 'projection', 'scene', 'showlegend', 'stream', 'surfaceaxis', 'surfacecolor', 'text', 'textfont', 'textposition', 'textpositionsrc', 'textsrc', 'texttemplate', 'texttemplatesrc', 'transforms', 'type', 'uid', 'uirevision', 'visible', 'x', 'xcalendar', 'xhoverformat', 'xsrc', 'y', 'ycalendar', 'yhoverformat', 'ysrc', 'z', 'zcalendar', 'zhoverformat', 'zsrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'
Warning: 'scatter3d' objects don't have these attributes: 'col'
Valid attributes include:
'connectgaps', 'customdata', 'customdatasrc', 'error_x', 'error_y', 'error_z', 'hoverinfo', 'hoverinfosrc', 'hoverlabel', 'hovertemplate', 'hovertemplatesrc', 'hovertext', 'hovertextsrc', 'ids', 'idssrc', 'legendgroup', 'legendgrouptitle', 'legendrank', 'line', 'marker', 'meta', 'metasrc', 'mode', 'name', 'opacity', 'projection', 'scene', 'showlegend', 'stream', 'surfaceaxis', 'surfacecolor', 'text', 'textfont', 'textposition', 'textpositionsrc', 'textsrc', 'texttemplate', 'texttemplatesrc', 'transforms', 'type', 'uid', 'uirevision', 'visible', 'x', 'xcalendar', 'xhoverformat', 'xsrc', 'y', 'ycalendar', 'yhoverformat', 'ysrc', 'z', 'zcalendar', 'zhoverformat', 'zsrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'
table(dfFiltrados$RACE)
1 2 3 4 5
3370 426 31 6 51
#Cinco niveles, WHITE = 1, BLACK = 2, ORIENTAL = 3, AMERICAN INDIAN = 4, MIXED = 5.
#Absoluta disparidad de muestreo en cuanto a raza.
table(dfFiltrados$SEX)
1 2
1972 1912
#En cuanto a sexo no
Las personas mas pesadas, desarollan piernas mas anchas para soportar su peso que alguien de su misma altura menos pesada?
Podemos identificar a las personas con enanismo? ademas de menor altura para su edad, que otras variables tienen fundamentalmente distintas?
A que edad pegan “el estiron” los hombres y cuando las mujeres? existe un momento concreto? Ademas de altura, que otras medidas cambian considerablemente? (medida de cintura en mujeres por ej, ensanchamiento de espalda hombres?)